package cn.com.bluemoon.daps.model.controller.api;


import cn.com.bluemoon.daps.api.model.RemoteModeUserAccreditService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants.DapsApiModel;
import cn.com.bluemoon.daps.common.datascope.BmPermission;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.model.entity.DapDataModelUserAccredit;
import cn.com.bluemoon.daps.model.service.DapDataModelUserAccreditService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Api(tags = {"FeignClient服务-模型授权"})
@RequestMapping(DapsApiModel.API_MODEL_USER_ACCREDIT)
@BmPermission(value = "", name = "服务注册-模型授权", ignore = true)
@RestController
@Slf4j
public class DapDataModelUserAccreditApi implements RemoteModeUserAccreditService {

    @Resource
    DapDataModelUserAccreditService userAccreditService;

    /**
     * 模型+用户信息
     *
     * @return 模型+用户信息
     */
    @GetMapping("/")
    public ResultBean<Map<String, List<DapDataModelUserAccredit>>> listByModel() {
        List<DapDataModelUserAccredit> list = userAccreditService.list(userAccreditService.bmLambdaQuery());
        Map<String, List<DapDataModelUserAccredit>> modelIdAndUserAccredit = list.stream().collect(Collectors.groupingBy(DapDataModelUserAccredit::getModelId));
        return ResultBean.ok(modelIdAndUserAccredit);
    }
}
